<template>
  <div class="detail">
    <c-title :hide="false" :text="text"></c-title>
    <header class="header">
      <div>
        <van-image width="6.0625rem" height="6.2813rem" :src="form.avatar_image" />
        <div class="office-status" v-if="lawyer_type == 'office'">
          <span>{{ form.status == 1 ? '经营' : '休息' }}</span>
        </div>
      </div>
      <div class="header-info">
        <div class="header-name">{{ lawyerInfo.name }} </div>
        <div class="header-title-year" v-if="lawyer_type == 'lawyer'">
          <span>{{ lawyerInfo.title }}</span>
          <span>执业{{ lawyerInfo.year }}年</span>
        </div>
        <ul class="header-domain-wrapper" v-if="lawyer_type == 'lawyer'">
          <li class="header-domain-item" v-for="(item, i) in domain_nickName" :key="item.id">{{ item.title }}<span
              class="right-line" v-if="domain_nickName.length !== i + 1"></span></li>
        </ul>
        <div style="font-size: 0.875rem;" v-if="lawyer_type == 'lawyer'">咨询次数：{{ lawyerInfo.consult_time }}</div>
        <div class="header-tel" v-if="lawyer_type == 'office'">电话：{{ lawyerInfo.tel }}</div>
        <div class="header-address" v-if="lawyer_type == 'office'">地址：{{ address }}</div>
      </div>
      <div class="header-nav" v-if="lawyer_type == 'lawyer'">
        <span v-for="(item, i) in nav_text" :key="item" @click="toggle_title(i)" :class="{ 'nav-text': nav_index == i }"
          style="color: #666; font-size: 1rem; background: #fff; flex: 1;">{{ item }}</span>
      </div>
    </header>
    <main class="main" :class="{'w100':lawyer_type!=='lawyer'}">
      <template v-if="nav_index == 0">
        <div class="desc" v-if="lawyer_type == 'lawyer'">
          <div class="basic-info-title">基本信息</div>
          <ul class="desc-content">
            <li class="basic-info">
              <span class="key">性别：</span>
              <span class="value">{{ lawyerInfo.gender == "1" ? '男' : '女' }}</span>
            </li>
            <li class="basic-info">
            <span class="key">执业年限：</span>
            <span class="value">{{lawyerInfo.year}}年</span>
          </li>
            <!-- <li class="basic-info">
            <span class="key">职称：</span>
            <span class="value">{{lawyerInfo.title}}</span>
          </li> -->
            <li class="basic-info" @click="link">
              <span class="key">所属律所：</span>
              <span class="value">{{ lawfirmName }}</span>
            </li>
            <li class="basic-info">
              <span class="key">服务区域：</span>
              <span class="value">{{ lawyerInfo.show_address }}</span>
            </li>
            <li class="basic-info">
              <span class="key">执业证号：</span>
              <span class="value">{{ lawyerInfo.number }}</span>
            </li>
            <!-- <li class="basic-info">
              <div class="key photo">执业照片：</div>
              <van-image width="7.5rem" height="7.5rem" :src="lawyerInfo.number_thumb_image" />
            </li> -->
          </ul>
        </div>
        <div class="desc">
          <div class="basic-info-title">简介</div>
          <div class="desc-content">{{ lawyerInfo.introduction }}</div>
        </div>
        <div class="desc">
          <div class="basic-info-title">证件执照</div>
          <div class="desc-content"> <van-image width="7.5rem" height="7.5rem" :src="lawyerInfo.number_thumb_image" />
          </div>
        </div>
        <template v-if="lawyer_type == 'office'">
          <div class="desc">
            <div class="basic-info-title">资质</div>
            <van-image width="7.5rem" height="7.5rem" :src="lawyerInfo.thumb_image" />
          </div>
          <div class="lawyer">
            <div class="basic-info-title">律师</div>
            <keep-alive>
              <lawyerPlatform :request="false" :lawyers="lawyerInfo.lawyers" :lawfirmName="lawyerInfo.name" />
            </keep-alive>
          </div>
        </template>
      </template>
      <template v-else>
        <div class="lawyer-serve" v-if="lawyer_type == 'lawyer'">
          <div class="basic-info-title" style="text-align: left;">法律服务</div>
          <div style="margin-left: -0.6rem;">
            <keep-alive>
              <lawyerServe :listServe="listServe" @consult="consultHandle" />
            </keep-alive>
          </div>
        </div>
      </template>

    </main>
  </div>
</template>

<script>
import lawyerPlatform from "./components/lawyer-platform";
import lawyerServe from "./components/lawyer-serve";
import { Image } from "vant";
export default {
  data() {
    return {
      nav_index: 0,
      nav_text: ['律师简介', '法律服务'],
      text: "",
      lawyer_type: "",
      order_type: "",
      httpUrl: "",
      lawyerId: "",
      listServe: [],//律师服务列表
      domain_nickName: [],//领域名称
      lawyerInfo: {},//律师详情
      lawfirmName: "",
      address: "",
      form: {
        avatar: "",
        status: 1,
        introduction: "",
        thumb_image: "",
        address: "",
      },
      streetId: "",
      areaId: "",
      cityId: "",
      provinceId: "",
      streetName: "",
      id: ""
    };
  },
  methods: {
    toggle_title(index) {
      this.nav_index = index;
    },
    //服务咨询
    consultHandle({ amount, consult_type, goods_id, service_day }) {
      let json = {
        service_day,
        goods_id,
        l_id: this.lawyerInfo.id,
        price: amount,
        service_type: consult_type == 0 ? 1 : 2,
        l_name: this.lawyerInfo.name,
        lf_id: this.lawyerInfo.lf_id,
        lf_name: this.lawyerInfo.lawyer_firm.name,
        lf_province_name: this.lawyerInfo.lawyer_firm.lf_province_name,
        lf_city_name: this.lawyerInfo.lawyer_firm.lf_city_name,
        lf_area_name: this.lawyerInfo.lawyer_firm.lf_area_name,
        lf_street_name: this.lawyerInfo.lawyer_firm.lf_street_name,
        lf_address_detail: this.lawyerInfo.lawyer_firm.address_detail
      }
      $http.post("plugin.lawyer-platform.frontend.controllers.create", json).then(res => {
        if (res.result == 1) {
          let order_ids = res.data.order_ids
          this.$router.push(this.fun.getUrl("orderpay", { order_ids }))
        } else {
          this.$toast(res.msg)
        }
      })
    },
    link() {
      this.text = "律所详情";
      this.$router.push(this.fun.getUrl("lawyerDetail", { id: this.lawyerInfo.lf_id }, { order_type: "office" }));
    },
    getData() {
      let url = this.lawyer_type == 'lawyer' ? "plugin.lawyer-platform.frontend.controllers.lawyer.getDetail" : "plugin.lawyer-platform.frontend.controllers.lawyer-firm.getDetail";
      $http.post(url, { id: this.id }).then(res => {
        if (res.result == 1) {
          let data = res.data.detail;
          this.lawyerInfo = data;
          this.domain_nickName = data.category_data;
          if (this.lawyer_type == 'office') {
            this.areaId = data.address.area,
              this.cityId = data.address.city,
              this.provinceId = data.address.province;
            this.form.avatar_image = data.logo_image;
            this.streetId = data.address.stree;
            let province = JSON.parse(localStorage.getItem("province")),
              city = JSON.parse(localStorage.getItem("city")),
              area = JSON.parse(localStorage.getItem("district")),
              provinceName = province.filter(item => item.id == this.provinceId),
              cityName = city.filter(item => item.id == this.cityId),
              districtName = area.filter(item => item.id == this.areaId);
            this.address = provinceName[0].areaname + cityName[0].areaname + districtName[0].areaname;
            this.getStreet()
          } else {
            this.lawfirmName = data.lawyer_firm.name
            this.listServe = data.goods;
            this.form.avatar_image = data.avatar_image;
          }
          this.form.status = data.status;
        }
      })
    },
    getStreet() {
      $http
        .get("member.memberAddress.street", {
          district_id: this.areaId
        })
        .then(response => {
          if (response.result === 1 && !this.fun.isTextEmpty(response.data)) {
            if (this.streetId) {
              response.data.forEach(item => {
                if (item.id == this.streetId) {
                  this.streetName = item.areaname
                }
              })
            }
            if (!this.fun.isTextEmpty(response.data) && response.data.length > 0) {
              this.address += this.streetName
            }
          }
        })
        .catch(error => {
          this.strShow = false;
          console.log(error);
        });
    }
  },
  activated() {
    if (document.documentElement.scrollTop !== 0) {
      document.documentElement.scrollTo(0, 0)
    }
    this.lawyer_type = this.$route.query.order_type;
    this.id = this.$route.params.id;
    if (this.$route.query.order_type == 'office') {
      this.text = '律所详情';
      this.httpUrl = "plugin.lawyer-platform.frontend.controllers.lawyer-firm.getLawyerList";
      this.lawyerId = this.$route.params.id;
    } else {
      this.text = '律师详情';

    }
    this.getData()
  },
  components: {
    VanImage: Image,
    lawyerPlatform,
    lawyerServe
  }
};
</script>

<style lang="scss" scoped>
.lawyer-serve {
  padding: 1.3438rem;
}

.office-status {
  margin-top: 0.6rem;

  span {
    width: 3.125rem;
    border: 1px solid #808080;
    padding: 0.1rem 0.8rem;
  }
}

.header-domain-wrapper {
  display: flex;
  flex-wrap: wrap;

  .header-domain-item {
    position: relative;
    padding-right: 0.3125rem;
    margin-right: 0.3125rem;
    text-align: center;
    font-size: 0.75rem;
    color: #666;
    margin-bottom: 0.625rem;
  }

  .right-line {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 2px;
    height: 65%;
    background: #666;
  }
}

.detail::-webkit-scrollbar {
  display: none;
}

.detail {
  min-height: 100vh;

  .photo {
    margin-bottom: 0.5rem;
  }

  .basic-info {
    margin: 0.5rem 0;
  }

  .key {
    color: #6b6b6b;
  }

  .value {
    color: #1f1f1f;
  }
}

.title {
  color: #282828;
  margin-bottom: 0.8rem;
}

.detail::-webkit-scrollbar {
  display: none;
}

.w100 {
  width: 100%;
  height: 100%;
  margin-left: 0 !important;
  margin-right: 0 !important;
  padding-bottom: 0 !important;

  .lawyer {
    margin-bottom: 0 !important;
  }
}

.main {
  background: #fff;
  margin-left: 0.625rem;
  margin-right: 0.625rem;
  padding-bottom: 9.375rem;

  .basic-info-title {
    position: relative;
    color: #000;
    font-size: 1rem;
    margin-bottom: 0.7813rem;

    &::after {
      content: "";
      position: absolute;
      width: 0.4063rem;
      height: 1.0938rem;
      background: #f1e5ad;
      opacity: 1;
      border-radius: 0.1875rem;
      left: -0.6rem;
      top: 10%;
    }
  }

  .desc {
    padding: 1.3438rem;
    text-align: left;
    overflow: hidden;
  }

  .lawyer {
    padding: 1.3438rem;
  }

  .title {
    text-align: left;
  }

  .lawyer {
    text-align: left;
    margin-bottom: 1.8rem;
    overflow: hidden;

    .title {
      margin-left: 1rem;
    }
  }

  .desc-content {
    color: #6b6b6b;
  }
}

.header {
  position: relative;
  display: flex;
  padding: 1rem 0.625rem 3.4688rem;
  background-color: rgba(245, 211, 119, 100);

  .header-nav {
    position: absolute;
    bottom: 0;
    left: 0.625rem;
    right: 0.625rem;
    height: 2.6563rem;
    line-height: 2.6563rem;
    display: flex;
    justify-content: space-evenly;
    border-top-left-radius: 0.625rem;
    border-top-right-radius: 0.625rem;
    overflow: hidden;
  }

  .nav-text {
    color: #000 !important;
    background: #f1e5ad !important;
  }

  .header-title-year {
    margin-top: 0.4688rem;
    margin-bottom: 0.3438rem;
    display: flex;
    align-items: center;

    span {
      font-size: 0.75rem;
      color: #fff;
      background: #a78d25;
      border-radius: 0.1875rem;
      padding: 0.0625rem 0.3125rem;
      margin-right: 0.3125rem;
    }
  }
}

::v-deep .van-image__img {
  border-radius: 0.25rem;
}

.header-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: baseline;
  margin-left: 0.5rem;

  .header-name {
    font-size: 1.1875rem;
  }

  .header-tel,
  .header-address {
    margin-top: 0.8rem;
    color: #3f3f3f;
    font-size: 0.8rem;
  }
}
</style>
